package cn.netjava.softkid.chapter11;

import java.awt.Dimension;
import java.awt.FlowLayout;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class SwingTest  {


	public  void test() {
		JFrame s = new JFrame();
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int width = screenSize.width;
		int height = screenSize.height;

		s.setSize(width/2, height/2);
		s.setLocation(width/4, height/4);
		
		FlowLayout layout = new FlowLayout();
		s.setLayout(layout);
		
		button1 = new JButton("Button1");
		button1.setSize(50, 50);
		
		button2 = new JButton("Button2");
		s.add(button1);
		s.add(button2);
		
		
		label = new JLabel("label");
		s.add(label);
		
		field = new JTextField("field",10);
		s.add(field);
		
		area = new JTextArea(10,10);
		s.add(area);
		
		button2.addActionListener(
				new ActionListener()
				{
					public void actionPerformed(ActionEvent event)
					{
						processAction();
					}
				}
		);
		

		s.setResizable(true);
		s.setVisible(true);
		s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void processAction()
	{
		String str = field.getText();
		button1.setText(str);
		button2.setText(str);
		area.append(str);
		label.setText(str);
		
	}
	private JButton button1;
	private JButton button2;
	private JTextField field;
	private JTextArea area;
	private JLabel label;
	public static void main(String args[])
	{
		SwingTest s = new SwingTest();
		s.test();
		
	}
}
